//
//  DataModal.h
//  myp1
//
//  Created by go2matrix on 13-10-29.
//  Copyright (c) 2013年 go2matrix. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#import "MBProgressHUD.h"

@class DataModal;

@protocol  DataModalProtocol
-(NSDictionary *)modalUrl;
-(void)processSuccess:(NSDictionary *)results ;
@optional
-(void)processFailed:(NSDictionary *)results ;
@end

@interface DataModal : NSObject<NSURLConnectionDelegate,MBProgressHUDDelegate>{
}

@property (nonatomic, weak) IBOutlet NSObject<DataModalProtocol>* delegate;
@property (nonatomic, weak) NSNumber *tag;

@property (nonatomic,retain) NSManagedObjectContext *managedObjectContext;
+ (DataModal *)instance;

-(void)execute:(NSObject <DataModalProtocol>*)modal withhud:(BOOL)withhud;
-(void)executeModal:(NSObject <DataModalProtocol>*)modal withhud:(BOOL)withhud completion:(void (^)(NSDictionary *data))completionHandler
       failure:(void(^)())failureHandler;
//执行http请求

//执行查询
-(NSArray *)queryUniqueData :(NSString *)entityName fieldname:(NSString *)fieldname;
//执行查询
-(NSArray *)queryData :(NSString *)entityName whereString:(NSString *)whereString;
//执行查询
-(NSArray *)queryData :(NSString *)entityName whereString:(NSString *)whereString order:(NSString *)order;
-(NSArray *)queryData :(NSString *)entityName whereString:(NSString *)whereString order:(NSString *)order ascending:(BOOL)ascending;

//创建新纪录
-(NSManagedObject *)createNewItem :(NSString *)entityName;
//删除表内数据
-(void )deleteEntity :(NSString *)entityName  whereString:(NSString *)whereString;
//删除一条数据
-(void )deleteObject :(NSManagedObject *)object;



+(id) createDataModal:(NSString *)className;
+(void) copyDictionary:(NSDictionary *)dict toItem:(NSObject *)object;

@end

@interface DataModalBasic :NSObject
@property(nonatomic) BOOL hasHud;
@property(nonatomic,strong) id hud;

@end

